/******************************************************************************
 * * ui_nvm_stru.h - data structure of nvram
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#ifndef _UI_NVM_STRU_H_
#define _UI_NVM_STRU_H_

#ifdef __cplusplus
extern "C" {
#endif /* __cpluscplus */

#ifndef __packed
#define __packed                       __attribute__((packed))
#endif

#define NV_SETTING_MAX_SIM_NAME_LEN    10
typedef struct
{
    UINT8 DefaultSim4Call;                                // defualt SIM for call
    UINT8 DefaultSim4msg;                                 // defualt SIM for message
    UINT8 DefaultSim4Standby;                             // defualt SIM for standby
    INT8  SimName[2][NV_SETTING_MAX_SIM_NAME_LEN];        // SIM name for SIM1 and SIM2 ::string
} __packed NV_Setting_Dual_Setting_t;

typedef struct
{
    UINT8 CurrentRingToneIndex[2];                          // current ring index in g_RingToneList for two SIM
    UINT8 RingVolume;                                       // refer to Hal interface
    UINT8 KeypadToneVolume;                                 // refer to Hal interface
    UINT8 VibratingStat;                                    // Vibrating status
    UINT8 MsgAlertStat[2];                                  // message alert status for two SIM
    UINT8 CurrentMsgToneIndex[2];                           // for two SIM, Valid when MsgAlertStat is SETTING_MSG_ALERT_RING
    UINT8 WarningToneStat;                                  // warning tone status
} __packed NV_Setting_Tone_Setting_t;

typedef struct
{
    UINT8 CurrentWallPaperIndex;                          // current wall paper index
    UINT8 BacklightIntensity;                             // backlight intensity level
    UINT8 BacklightTimeout;                               // backlight timeout value
    UINT8 StandbyScreenMode;                              // screen standby mode
} __packed NV_Setting_Display_Setting_t;

#define NV_SETTING_MAX_PROFILE_NUM    5
typedef struct
{
    UINT8 ProfileActivateIdx;                               // current Activate profile index
    NV_Setting_Tone_Setting_t ProfileSetting[NV_SETTING_MAX_PROFILE_NUM];
} __packed NV_Setting_Profile_Setting_t;

typedef struct
{
    UINT8 TimeFormat;                                        // format of time display
    UINT8 TimeDisplay;                                       // show time on desktop or not
    UINT8 TimeAutoUpdate;                                    // automatic update time on/off
} __packed NV_Setting_Time_Setting_t;

typedef struct
{
    BOOL AutoRedialOn;                                       // true means auto redial on
} __packed NV_Setting_Call_Setting_t;

#define NV_SETTING_MAX_WELCOME_NOTE_CHARS_NUM    20          // the maximal number of characters
#define NV_SETTING_MAX_WELCOME_NOTE_STR_LEN      (NV_SETTING_MAX_WELCOME_NOTE_CHARS_NUM * 3 + 1)

typedef struct
{
    UINT8  CurrentLanguage;                                   // current language setting
    BOOL   AutoGuardOn;                                       // true means auto guard on.
    UINT16 AutoGuardDelay;                                    // delay in second for auto guard starting.
    BOOL   KeyguardOn;                                        // true means keyguard on.
    UINT8  PlmnSearchMode[2];                                 // plmn search mode
    BOOL   StartupToneOn;                                     // true means start-up tone on.
    BOOL   WelcomeNoteOn;                                     // true means welcome note will be displayed
    INT8   WelcomeNote[NV_SETTING_MAX_WELCOME_NOTE_STR_LEN];  // max length of welcome note   ::string
    BOOL   FlightModeOn;                                      // true means flight mode on.
} __packed NV_Setting_Phone_Setting_t;

#define NV_SETTING_SECURITY_CODE_LEN    4
typedef struct
{
    UINT8 SecurityCode[NV_SETTING_SECURITY_CODE_LEN];          // 4 bytes security code
    UINT8 SecurityStatus;                                      // security code request status
} __packed NV_Setting_Security_Setting_t;

typedef struct
{
    NV_Setting_Dual_Setting_t     DualSimSetting;
    NV_Setting_Tone_Setting_t     ToneSetting;
    NV_Setting_Display_Setting_t  DisplaySetting;
    NV_Setting_Profile_Setting_t  Profile_Setting;
    NV_Setting_Time_Setting_t     TimeSetting;
    NV_Setting_Call_Setting_t     CallSetting;
    NV_Setting_Phone_Setting_t    PhoneSetting;
    NV_Setting_Security_Setting_t SecuritySetting;
} __packed NV_UI_Settings_t;

#define NV_CALL_MAX_E_NUM_CNT     5
#define NV_CALL_MAX_E_NUM_SIZE    5
typedef struct
{
    UINT8 ENumberCnt;
    INT8  ENumber[NV_CALL_MAX_E_NUM_CNT][NV_CALL_MAX_E_NUM_SIZE];   // ::string
} __packed NV_UI_Call_ENumber_t;

typedef struct
{
    UINT8                HandsetVolume; // Handset volume. See HAL_SPEAKER_GAIN in hal.h
    UINT8                SpeakerVolume; // Speaker volume. See HAL_SPEAKER_GAIN in hal.h
    NV_UI_Call_ENumber_t EmergencyNumber;
} __packed NV_UI_Call_t;

#define NV_CONTACTS_MAX_NAME_LEN      41
#define NV_CONTACTS_MAX_NUMBER_LEN    31
#ifdef NV_USE_RAM
#define NV_CALL_LOG_MAX_NUM           30  // for crane_bare test
#else
#define NV_CALL_LOG_MAX_NUM           100
#endif

typedef struct
{
    UINT8  Type;                               // Call log type
    UINT8  SimId;                              // SIM ID
    UINT32 Timestamp;                          // Call time
    UINT32 Duration;                           // Call duration
    INT8   Number[NV_CONTACTS_MAX_NUMBER_LEN]; // Remote party number ::string
    INT8   Name[NV_CONTACTS_MAX_NAME_LEN];     // Remote party name  ::string
} __packed NV_Call_Log_Data_t;

typedef struct
{
    NV_Call_Log_Data_t CallLog[NV_CALL_LOG_MAX_NUM];
    UINT8              UnreadMissedCalls;
} __packed NV_UI_Call_Log_t;

#define NV_FRAMEWORK_MAX_APP_NUM    20

typedef struct
{
    UINT16 AppNameTextId[NV_FRAMEWORK_MAX_APP_NUM];                // for go to
} __packed NV_UI_Framework_t;

typedef struct
{
    INT8  Name[NV_CONTACTS_MAX_NAME_LEN];                          // ::string
    INT8  Number[NV_CONTACTS_MAX_NUMBER_LEN];                      // ::string
    UINT8 ToneIndex;
} __packed NV_UI_Contacts_Contact_Info_t;

#ifdef NV_USE_RAM
#define NV_CONTACTS_MAX_CONTACT_NUM    30 // for crane_bare test
#else
#define NV_CONTACTS_MAX_CONTACT_NUM    1000
#endif

typedef struct
{
    NV_UI_Contacts_Contact_Info_t ContactInfo[NV_CONTACTS_MAX_CONTACT_NUM];
} __packed NV_UI_Contacts_Contact_List_t;

#define NV_CONTACTS_MAX_BITMAP_LEN    (NV_CONTACTS_MAX_CONTACT_NUM / 8 + 1)

typedef struct
{
    UINT8 ContactBitmap[NV_CONTACTS_MAX_BITMAP_LEN];          // ContactBitmap[0]: ContactInfo[0] to [7], ContactBitmap[1]: ContactInfo[8] to [15], and so on. bit 1: present, bit 0: absent
    UINT8 MemSelBitmap;                                       // default 7
} __packed NV_UI_Contacts_Bitmap_t;

typedef struct
{
    INT8 Name[NV_CONTACTS_MAX_NAME_LEN];                      // ::string
    INT8 Number[NV_CONTACTS_MAX_NUMBER_LEN];                  // ::string
} __packed NV_UI_Contacts_Speed_Dial_Info_t;

#define NV_CONTACTS_MAX_SPEED_DIAL_KEY_NUM    8                // key 2 to 9
typedef struct
{
    NV_UI_Contacts_Speed_Dial_Info_t SpeedDialInfo[NV_CONTACTS_MAX_SPEED_DIAL_KEY_NUM];
} __packed NV_UI_Contacts_Speed_Dial_List_t;

#define NV_CONTACTS_MAX_NUMBER_IN_SCRN_LIST_NUM    10
typedef struct
{
    INT8 Number[NV_CONTACTS_MAX_NUMBER_IN_SCRN_LIST_NUM][NV_CONTACTS_MAX_NUMBER_LEN];  // ::string
} __packed NV_UI_Contacts_Num_Scrn_List_t;

typedef struct
{
    BOOL  OnOff;                                                  // TRUE: on, FALSE: off
    UINT8 Hour;                                                   // [0, 23]
    UINT8 Min;                                                    // [0, 59]
    UINT8 RepeatBitmap;                                           /* Bit 7: 0 means alarm once, 1 means repeat alarm */
                                                                  /* Bit 0 – 6 are valid if bit 7 is 1 */
                                                                  /* Bit 0: Sunday, bit 1: Monday ... bit 6: Saturday, refers to Hal_Rtc_t */
    UINT8 RepeatCount;                                            // Add one if snooze or stop automatically, alarm rings again after a fixed interval of time
} __packed NV_UI_Alarm_Info_t;

#define NV_ALARM_MAX_ALARM_NUM    2
typedef struct
{
    NV_UI_Alarm_Info_t AlarmInfo[NV_ALARM_MAX_ALARM_NUM];
    UINT8              ToneIndex;
} __packed NV_UI_Alarm_t;

#define NV_CALENDAR_MAX_REMINDER_LEN    46
typedef struct
{
    UINT16 Year;
    UINT8  Mon;                                                   // [1, 12]
    UINT8  Day;                                                   // [1, 31]
    UINT8  Wday;                                                  // Sunday = 0
    UINT8  Hour;                                                  // [0, 23], not set if 0xFF
    UINT8  Min;                                                   // [0, 59], not set if 0xFF
    INT8   Text[NV_CALENDAR_MAX_REMINDER_LEN];                    // not set if Text[0] is '\0' ::string
} __packed NV_UI_Calendar_Reminder_t;

#define NV_CALENDAR_MAX_REMINDER_NUM    10
typedef struct
{
    NV_UI_Calendar_Reminder_t Reminder[NV_CALENDAR_MAX_REMINDER_NUM];
} __packed NV_UI_Calendar_t;

#define NV_SMS_MAX_NAME_NUM    41

typedef struct
{
    INT8 ListName[NV_SMS_MAX_NAME_NUM];                            // ::string
} __packed NV_UI_Sms_Distribution_List_Name_t;

#ifdef NV_USE_RAM
#define NV_SMS_MAX_LIST_NUM    2 // for crane_bare test
#else
#define NV_SMS_MAX_LIST_NUM    10
#endif

typedef struct
{
    UINT8                              Count;
    NV_UI_Sms_Distribution_List_Name_t DistriList[NV_SMS_MAX_LIST_NUM];
} __packed NV_UI_Sms_Distribution_List_t;

typedef struct
{
    INT8 ContactName[NV_SMS_MAX_LIST_NUM][NV_SMS_MAX_NAME_NUM];                         // ::string
} __packed NV_UI_Sms_Distribution_Contact_Name_t;

typedef struct
{
    UINT8                                 Count;
    NV_UI_Sms_Distribution_Contact_Name_t ContactsList[NV_SMS_MAX_LIST_NUM];
} __packed NV_UI_Sms_Distribution_Contacts_List_t;

#define NV_SMS_MAX_INPUT_NUM    1681

typedef struct
{
    INT8 DraftContent[NV_SMS_MAX_INPUT_NUM];                       // ::string
} __packed NV_UI_Sms_Draft_Content_t;

#ifdef NV_USE_RAM
#define NV_SMS_MAX_DRAFTS_NUM    2 // for crane_bare test
#else
#define NV_SMS_MAX_DRAFTS_NUM    10
#endif

typedef struct
{
    UINT8                     Count;
    NV_UI_Sms_Draft_Content_t Drafts[NV_SMS_MAX_DRAFTS_NUM];
} __packed NV_UI_Sms_Drafts_t;
#define NV_SMS_MAX_FLG_NUM    2
typedef struct
{
    UINT8 DictionaryFlg;
    UINT8 DeliveryRepFlg[NV_SMS_MAX_FLG_NUM];
} __packed NV_UI_Sms_t;

enum
{
    NV_AUDIO_ORDER_PLAY = 0,
    NV_AUDIO_SHUFFLE_PLAY,
    NV_AUDIO_ALL_REPEAT_PLAY,
    NV_AUDIO_REPEAT_ONCE_PLAY,
    NV_AUDIO_MODE_MAX
};

typedef UINT8 NV_AUDIO_PLAYER_MODE;

typedef struct
{
    NV_AUDIO_PLAYER_MODE audio_player_mode;
} __packed NV_UI_Audio_Player_t;


#define NV_BLUETOOTH_MAX_DEV_CNT   10
#define NV_BLUETOOTH_DEV_NAME_LEN  48
typedef struct
{
    UINT8 on_off;
    UINT8 dev_cnt;
    INT8 local_name[NV_BLUETOOTH_DEV_NAME_LEN];
    INT8 dev_name[NV_BLUETOOTH_MAX_DEV_CNT][NV_BLUETOOTH_DEV_NAME_LEN];
    INT8 addr[NV_BLUETOOTH_MAX_DEV_CNT][6];
    UINT32 cod[NV_BLUETOOTH_MAX_DEV_CNT];
    UINT8 length[NV_BLUETOOTH_MAX_DEV_CNT];
} __packed NV_UI_Bluetooth_t;

typedef struct
{
    NV_UI_Settings_t                       Settings;
    NV_UI_Framework_t                      Framework;
    NV_UI_Call_t                           Call;
    NV_UI_Call_Log_t                       CallLog;
    NV_UI_Contacts_Contact_List_t          ContactList;
    NV_UI_Contacts_Bitmap_t                ContactBitmap;
    NV_UI_Contacts_Speed_Dial_List_t       SpeedDialList;
    NV_UI_Contacts_Num_Scrn_List_t         NumScrnList;
    NV_UI_Alarm_t                          Alarm;
    NV_UI_Calendar_t                       Calendar;
    NV_UI_Sms_t                            Sms;
    NV_UI_Sms_Distribution_List_t          SmsDistriListInfo;
    NV_UI_Sms_Distribution_Contacts_List_t SmsDistriContactList;
    NV_UI_Sms_Drafts_t                     SmsDrafts;
    NV_UI_Audio_Player_t                   AudioPlayerMode;
    NV_UI_Bluetooth_t                      Bluetooth;
} __packed NV_UI_Stru_t;

enum
{
    NV_SECTION_UI_SETTINGS = 0,                         // NV_UI_Settings_t
    NV_SECTION_UI_FRAMEWORK,                            // NV_UI_Framework_t
    NV_SECTION_UI_CALL,                                 // NV_UI_Call_t
    NV_SECTION_UI_CALL_LOG,                             // NV_UI_Call_Log_t
    NV_SECTION_UI_CONTACTS_LIST,                        // NV_UI_Contacts_Contact_List_t
    NV_SECTION_UI_CONTACTS_BITMAP,                      // NV_UI_Contacts_Bitmap_t
    NV_SECTION_UI_SPEED_DIAL_LIST,                      // NV_UI_Contacts_Speed_Dial_Info_t
    NV_SECTION_UI_NUM_SCRN_LIST,                        // NV_UI_Contacts_Num_Scrn_List_t
    NV_SECTION_UI_ALARM,                                // NV_UI_Alarm_t
    NV_SECTION_UI_CALENDAR,                             // NV_UI_Calendar_t
    NV_SECTION_UI_SMS,                                  // NV_UI_Sms_t
    NV_SECTION_UI_SMS_DIST_LIST,                        // NV_UI_Sms_Distribution_List_t
    NV_SECTION_UI_SMS_DIST_CONT_LIST,                   // NV_UI_Sms_Distribution_Contacts_List_t
    NV_SECTION_UI_SMS_DRAFTS,                           // NV_UI_Sms_Drafts_t
    NV_SECTION_UI_AUDIO_PLAYER_MODE,                    // NV_SECTION_UI_AUDIO_PLAYER_MODE
    NV_SECTION_UI_BLUETOOTH,                            // NV_UI_Bluetooth_t
    NV_SECTION_UI_MAX_NUM
};
typedef UINT8 NV_UI_SECTION_ID;

/**
 * write to NVRAM
 * param (in) addr:  UINT32*
 * param (in) data:  UINT32*
 * param (in) len:   UINT32
 * return  UINT32: bytes have been writen
 */
extern UINT32 UI_NV_Write_Req(NV_UI_SECTION_ID SectionId, UINT32 OffSet, UINT32 Len, UINT8 *data);

/**
 * read data from NVRAM
 * param (in) SectionId:   UI_NV_SECTION_ID  section ID of NVM
 * param (in) OffSet:  UINT32                Offset in the Section
 * param (in) len:   UINT32                  Length of data to read
 * param (out) data:  UINT32*                data buffer
 * return  UINT32: bytes have been read
 */
extern UINT32 UI_NV_Read_Req(NV_UI_SECTION_ID SectionId, UINT32 OffSet, UINT32 Len, UINT8 *data);

/**
 * write default value to NVRAM for factory restore
 * return  void:
 */
extern VOID UI_NV_Restroe_Req(VOID);

/**
 * reset nv to default value
 * param (in) SectionId:   UI_NV_SECTION_ID  section ID of NVM
 * return  UINT8: 1 means reset done, 0 means not reset
 */
extern UINT8 UI_NV_Reset_Default(NV_UI_SECTION_ID);

#ifdef __cplusplus
}
#endif /* __cpluscplus */

#endif /* end of _UI_NVM_STRU_H_ */
